package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.domain.vo.NoticeIdReq;
import com.ruoyi.system.mapper.SysNoticeMapper;
import com.ruoyi.system.service.ISysNoticeService;
import com.ruoyi.web.controller.enums.NoticeTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 公告 信息操作处理
 * 
 * @author ruoyi
 */
@RestController
@Api(tags = "首页模块相关接口")
@RequestMapping("/home/notice")
public class NoticeHomeController extends BaseController
{
    @Autowired
    private ISysNoticeService noticeService;
    @Autowired
    SysNoticeMapper sysNoticeMapper;

    @GetMapping(value = "banner")
    @ApiOperation("首页轮播图")
    public AjaxResult banner()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.EIGHT.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        queryWrapper.last("limit 4");
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "top")
    @ApiOperation("头条新闻")
    public AjaxResult tops()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.ONE.getCode());
        queryWrapper.eq(SysNotice::getTop,1);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "new")
    @ApiOperation("最新公告")
    public AjaxResult newS()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.in(SysNotice::getNoticeType, Arrays.asList(NoticeTypeEnum.TWO.getCode(),NoticeTypeEnum.THREE.getCode(),NoticeTypeEnum.FOUR.getCode()));
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "zkzxjs")
    @ApiOperation("质控中心介绍")
    public AjaxResult zkzxjs()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.SEVEN.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "hydt")
    @ApiOperation("行业动态")
    public AjaxResult hydt()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.TWO.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "zkzxdt")
    @ApiOperation("质控中心动态")
    public AjaxResult zkzxdt()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.THREE.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "zkzxpx")
    @ApiOperation("质控中心培训")
    public AjaxResult zkzxpx()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.FOUR.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "yyjs")
    @ApiOperation("医院介绍")
    public AjaxResult yyjs()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.SIX.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }


    @GetMapping(value = "wyfc")
    @ApiOperation("委员风采")
    public AjaxResult wyfc()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.FIVE.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "jcbg")
    @ApiOperation("监测报告")
    public AjaxResult jcbg()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.NINE.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }

    @GetMapping(value = "ndbg")
    @ApiOperation("年度报告")
    public AjaxResult ndbg()
    {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(SysNotice::getNoticeId,SysNotice::getNoticeTitle,SysNotice::getNoticeContent,SysNotice::getNoticeUrl,SysNotice::getCreateTime);
        queryWrapper.eq(SysNotice::getNoticeType,NoticeTypeEnum.TEN.getCode());
        queryWrapper.eq(SysNotice::getStatus,0);
        queryWrapper.orderByDesc(SysNotice::getCreateTime);
        List<SysNotice> resultList = sysNoticeMapper.selectList(queryWrapper);
        return success(resultList);
    }


    @PostMapping(value = "detail")
    @ApiOperation("详情接口统一")
    public AjaxResult getInfo(@RequestBody  NoticeIdReq req)
    {
        return success(noticeService.selectNoticeById(req.getId()));
    }

}
